package com.solidit.cassandra.controller.persistance.util;


import java.util.List;

import org.apache.hadoop.hive.service.ThriftHive; 
import org.apache.hadoop.hive.service.ThriftHive.Client;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;

public class HiveTutorialThriftClient {
	private static Client getClient(String hiveServer, Integer hivePort) 
	{
	          final int SOME_BIG_NUMBER = 99999999;
	          
	        Client client=null;
	        try {
	             TSocket transport = new TSocket(hiveServer, hivePort);
	             transport.setTimeout(SOME_BIG_NUMBER);
	             transport.open();
	             TBinaryProtocol protocol = new TBinaryProtocol(transport);
	             client = new ThriftHive.Client(protocol);
	             return client;
	        }
	        catch (Exception e) {
	           e.printStackTrace();
	           return null;
	        }
	     }
	     
	     public static void main(String[] args) throws Exception 
	{
	     // Provide appropriate Server Hostname and Port number.
	          String HIVE_SERVER = "127.0.0.1";
	          Integer HIVE_PORT  = new Integer(10000);
	          
	          Client client = getClient(HIVE_SERVER, HIVE_PORT);
	          client.execute("SELECT * FROM geomanagement.persona");
	          final List<String> results = client.fetchAll();
	  		  for (String result : results) {
	  			System.out.println(result);
	  		}
	     }
	

}
